package com.vehicle.admin.web.common.shiro.listener;

import com.vehicle.admin.web.common.shiro.session.ShiroSessionRepository;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by yantingbin on 2017/7/18.
 */
@Component
public class ShiroSessionListener implements SessionListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(ShiroSessionListener.class);

    @Autowired
    private ShiroSessionRepository shiroSessionRepository;

    @Override
    public void onStart(Session session) {
        LOGGER.info("shiro session start");
    }

    @Override
    public void onStop(Session session) {
        LOGGER.info("shiro session stop");
    }

    @Override
    public void onExpiration(Session session) {
        shiroSessionRepository.deleteSession(session.getId());
    }
}
